package com.tangcco.controller;

import com.tangcco.biz.LyricsBiz;
import com.tangcco.biz.MusicBiz;
import com.tangcco.biz.SingerBiz;
import com.tangcco.pojo.Lyrics;
import com.tangcco.pojo.Music;
import com.tangcco.pojo.Singer;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/lyrics")
public class LyricsController {
	@Resource
	private LyricsBiz lyricsBiz;

	@Resource
	private MusicBiz musicBiz;

	@Resource
	private SingerBiz singerBiz;
	
	@RequestMapping("/getLyrics")
	public Object getLyrics(String musicRid, Model model){
		Singer singer = singerBiz.selectByMusicRid(musicRid);
//		String id = musicRid.substring(6);
		Music music = musicBiz.selectById(musicRid);
		List<Lyrics> lyrics = lyricsBiz.selectBySingerId(musicRid);
		List<String[]> lyricsList = new ArrayList<>();
        String[] strings = null;
		for (Lyrics lyric : lyrics) {
            strings = new String[2];
            strings[0] = lyric.getTime().toString();
            strings[1] = lyric.getLineLyric();
			lyricsList.add(strings);
		}
		model.addAttribute("lyricsList",lyricsList);
		model.addAttribute("music",music);
		model.addAttribute("s",singer);
		return "playmusic";
	}


}
